/**
 * 功能描述 行编辑
 */

define(function (require, exports, module){
	var EditGrid=require("editgrid");
	var store =require("store");
	var activeUser = store.get("user");
	
	var instance = {
			initComponent: function (params,widget){
				var optiongrid = new EditGrid({
					parentNode:".J-editgrid",
					autoRender:false,
					model:{
						id:"optiongrid",
						allowAdd:false,
						columns:[{
							name:"personalInfo.idNumber",
							label:"身份证号",
						},{
							name:"personalInfo.name",
							label:"姓名",
						},{
							name:"personalInfo.sex.value",
							label:"性别",
						},{
							name:"personalInfo.mobilePhone",
							label:"手机号",
						},{
							name:"travelContract.memberCertificates",
							label:"会员证号",
							format : function(value, row) {
								if(row.travelContract==null){
									return "";
								}else{
									return row.travelContract.member.personalInfo.idNumber
									+ "-"
									+ row.travelContract.member.personalInfo.name
									+ "-"
									+ row.travelContract.productRule.product.name
									+ "-"
									+ row.travelContract.memberCertificates;
								}
		        			},
							editor:{
								type : "autocomplete",
								url : "api/signupregister/search",
								queryParamName : "s",
								format : function(data) {
									return data.travelContract.member.personalInfo.idNumber
											+ "-"
											+ data.travelContract.member.personalInfo.name
											+ "-"
											+ data.travelContract.productRule.product.name
											+ "-"
											+ data.travelContract.memberCertificates;
			        			},
								params: function(){
									return {
										properties: "travelContract.memberCertificates",
										fetchProperties:"travelContract.pkTravelContract," +
												"travelContract.version,personalInfo.idNumber," +
												"personalInfo.sex.*,personalInfo.name," +
												"travelContract.member.personalInfo.idNumber," +
												"travelContract.member.personalInfo.name," +
												"travelContract.productRule.product.name," +
												"travelContract.memberCertificates," 
									};
								},
								onChange:function(plugin,index,rowData){
									rowData.travelContract = plugin.getData().travelContract;
									optiongrid.update(index,rowData);
								}
							},
						},{
							name:"checkInDate",
							label:"入住日期",
							editor:{
								type: "date",
								onEdit:function(editor,rowIndex,rowData){
									editor.setValue(rowData.checkInDate);
								},
								onChange:function(plugin,index,rowData){
									rowData.checkInDate = plugin.getValue();
									optiongrid.update(index,rowData);
								}
							},
							format:"date",
	        				formatparams:{
								mode:"YYYY-MM-DD"
							}
						},{

							name:"checkOutDate",
							label:"退房日期",
							editor:{
								type: "date",
								onEdit:function(editor,rowIndex,rowData){
									editor.setValue(rowData.checkOutDate);
								},
								onChange:function(plugin,index,rowData){
									rowData.checkOutDate = plugin.getValue();
									optiongrid.update(index,rowData);
								}
							},
							format:"date",
	        				formatparams:{
								mode:"YYYY-MM-DD"
							}
						
						}]
					}
				});
				widget.set("optiongrid",optiongrid);
			}
	};
	module.exports = instance;
});
